using AutoMapper;
using B.S.Data.MES.API.Applications.BaseData.Command.ChanXIanCommand;
using B.S.Domain.BasicData.Factory_modeling.Production_line_management;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.ChanXIanCommandHandlers
{
    /// <summary>
    /// 产线管理修改命令处理器
    /// </summary>
    public class UpdateChanXianCommandHandlers : IRequestHandler<UpdateChanXianCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<Production_line_management> proRepository;
        private readonly IMapper mapper;

        /// <summary>
        /// 构造函数，注入仓储和映射器
        /// </summary>
        /// <param name="proRepository">产线管理仓储</param>
        /// <param name="mapper">对象映射器</param>
        public UpdateChanXianCommandHandlers(IBaseRepository<Production_line_management> proRepository, IMapper mapper)
        {
            this.proRepository = proRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 处理产线管理修改命令
        /// </summary>
        /// <param name="request">修改命令</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>操作结果</returns>
        public async Task<APIRequst<int>> Handle(UpdateChanXianCommand request, CancellationToken cancellationToken)
        {
            
            Production_line_management productionLine = mapper.Map<Production_line_management>(request);
            productionLine.UpdateTime = DateTime.Now;
            productionLine.CreateTime = DateTime.Now;
            proRepository.Update(productionLine);
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            };
        }
    }
}
